﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using SevenInvaders.common;

namespace SevenInvaders
{

    class JoaoPlayer : Sprite
    {
        #region Atributos

        int player;

        animation animation1;

        Texture2D textureShoot;

        SoundEffect soundEffect;
        # endregion

        public JoaoPlayer(
            Texture2D texture,
            Vector2 position,
            int player,
            GameWindow gameWindow

            )
            : base(texture)
        {
            this.Position = position;

            this.player = player;

            this.Velocity = new Vector2(10, 10);

            this.Window = gameWindow;

            //this.soundEffect = Content.Load<SoundEffect>("ding");

            /*animation1 = new animation();
            animation1.frame.X = 0;
            animation1.frame.Y = 47;
            animation1.frame.Width = 30;
            animation1.frame.Height = 41;

            animation1.frames = 4;
            animation1.fps = 5;

            current_animation = animation1;*/
        }

        public JoaoPlayer(
            Texture2D texture,
            Vector2 position,
            int player,
            GameWindow gameWindow,
            Texture2D textureShoot,
            ContentManager Content
            )
            : base(texture)
        {
            this.Position = position;

            this.player = player;

            this.Velocity = new Vector2(10, 10);

            this.Window = gameWindow;

            /*animation1 = new animation();
            animation1.frame.X = 0;
            animation1.frame.Y = 47;
            animation1.frame.Width = 30;
            animation1.frame.Height = 41;

            animation1.frames = 4;
            animation1.fps = 5;

            current_animation = animation1;*/

            this.textureShoot = textureShoot;
        }

        public override void Update(GameTime gameTime)
        {

        }

        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public void Update(GameTime gameTime, KeyboardState ks, KeyboardState old_ks)
        {
            #region teclado

            if (ks.IsKeyDown(Keys.Right))
            {
                PositionX += Velocity.X;
            }
            else if (ks.IsKeyDown(Keys.Left))
            {
                PositionX -= Velocity.X;
            }
            if (ks.IsKeyDown(Keys.Down))
            {
                PositionY += Velocity.Y;
            }
            else if (ks.IsKeyDown(Keys.Up))
            {
                PositionY -= Velocity.Y;
            }

            if (ks.IsKeyDown(Keys.X) && !old_ks.IsKeyDown(Keys.X))
            {
                Shoot.list.Add(new Shoot(textureShoot, new Vector2(this.Position.X + this.current_animation.frame.Width / 2, this.Position.Y + 5), Shoot.Direction.UP, this.Velocity));
                //soundEffect.Play();
            }


            #endregion

            //se a nave sair pela esquerda nao deixar
            if (Position.X < 0)
            {
                PositionX = 0;
            }
            if (Position.X > 736)
            {
                PositionX = 736;
            }
            if (Position.Y < 0)
            {
                PositionY = 0;
            }
            if (Position.Y > 532)
            {
                PositionY = 532;
            }

            //se a nave sair pela direita nao deixar
            /* if (PositionX > Window.ClientBounds.Width - animation1.frame.Width)
             {
                 PositionX = Window.ClientBounds.Width - animation1.frame.Width;
             }

         }*/


        }
    }
}